package ar.edu.unicen.pladema.ui.model;

/**
 * Representación del fractal de Mandelbrot.
 * 
 * @author Sebastian Perruolo
 *
 */
public class CoordinatesMapping {
	public static double REAL_MIN=-1.5;
	public static double REAL_MAX=0.5;
	public static double IMAG_MIN = -1;
	public static double IMAG_MAX = 1;
//	private int wArea;
//	private int hArea;
	private double xMin;
//	private double xMax;
	private double yMin;
//	private double yMax;
	private double wm;
	private double hm;
	
	public CoordinatesMapping(int wArea, int hArea,
			double xMin, double xMax,
			double yMin, double yMax,
			boolean keepRatio) {
		xMin = xMin -5;
		yMin = yMin -5;
		//this.wArea = wArea;
		//this.hArea = hArea;
		this.xMin = xMin;
//		this.xMax = xMax;
		this.yMin = yMin;
//		this.yMax = yMax;
		this.wm = (xMax - xMin) / wArea;
		this.hm = (yMax - yMin) / hArea;
		if (keepRatio) {
			wm = Math.max(wm, hm);
			hm = wm;
		}
	}

	public double translateX(int x) {
		double dx = (new Double(x)).doubleValue();
		double rpart = dx * wm;
		return rpart + xMin;
	}

	public double translateY(int y) {
		double dy = (new Double(y)).doubleValue();
		double ipart = dy * hm;
		return ipart + yMin;
	}
	public int reverseX(double x) {
		double result = x - xMin;
		result = result / wm;
		return (new Double(result)).intValue();
	}
	public int reverseY(double y) {
		double result = y - yMin;
		result = result / hm;
		return (new Double(result)).intValue();
	}
}
